import { deptTreeSelect } from '@/api/SystemSetting/accounts'

const state = {
  deptTree: []
}

const mutations = {
  SET_DEPT_TREE(state, data) {
    state.deptTree = data
  }
}

const actions = {
  fetchDeptTree({ commit }) {
    return deptTreeSelect()
      .then((response) => {
        if (response && response.data) {
          commit('SET_DEPT_TREE', response.data)
        }
      })
      .catch((error) => {
        console.error('获取部门树结构失败:', error)
      })
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
